<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link th:href="@{/css/shop.css}" type="text/css" rel="stylesheet"/>
    <link th:href="@{/skin/default/skin.css}" rel="stylesheet" type="text/css" id="skin"/>
    <link th:href="@{/css/Sellerber.css}" type="text/css" rel="stylesheet"/>
    <link th:href="@{/css/bkg_ui.css}" type="text/css" rel="stylesheet"/>
    <link th:href="@{/font/css/font-awesome.min.css}" rel="stylesheet" type="text/css"/>
    <script th:src="@{/js/jquery-1.9.1.min.js}" type="text/javascript"></script>
    <script th:src="@{/js/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/js/bootstrap.min.js}" type="text/javascript"></script>
    <script th:src="@{/js/Sellerber.js}" type="text/javascript"></script>
    <script th:src="@{/js/shopFrame.js}" type="text/javascript"></script>
    <script type="text/javascript" th:src="@{/js/jquery.cookie.js}"></script>
    <title>用户登录</title>
</head>

<body class="login-layout Reg_log_style">
<div class="logintop">
    <span>欢迎后台管理界面平台</span>
    <ul>
        <li><a href="#">返回首页</a></li>
        <li><a href="#">帮助</a></li>
        <li><a href="#">关于</a></li>
    </ul>
</div>
<div class="loginbody">
    <div class="login-container">
        <div class="center"><img th:src="@{/images/logo.png}"/></div>
        <div class="space-6"></div>
        <div class="position-relative">
            <div id="login-box" class="login-box widget-box no-border visible">
                <div class="login-main">
                    <div class="clearfix">
                        <div class="login_icon"><img th:src="@{/images/login_img.png}"/></div>

                        <h4 class="title_name"><img th:src="@{/images/login_title.png}"/></h4>
                        <fieldset>
                            <ul>
                                <li><input type="hidden" name="adminId"/></li>
                                <li class="frame_style form_error"><label class="user_icon"></label><input
                                        name="username"
                                        type="text"
                                        data-name="用户名"
                                        id="username"/><i>用户名</i>
                                </li>
                                <li class="frame_style form_error"><label class="password_icon"></label><input
                                        name="password" type="password" data-name="密码" id="userpwd"/><i>密码</i></li>
                                <li class="frame_style form_error">
                                    <label class="Codes_icon"></label>
                                    <input name="" type="text" data-name="验证码" name="Codes_text" id="Codes_text"/>
                                    <i>验证码</i>
                                    <div class="Codes_region">
                                        <img id="checkImg" th:src="@{/admin/getValicode}" width="100%"
                                             height="38px">
                                    </div>
                                </li>
                            </ul>
                            <div class="space"></div>
                            <div class="clearfix">
                                <label class="inline">
                                    <input type="checkbox" class="ace">
                                    <span class="lbl">保存密码</span>
                                </label>

                                <button id="login_btn" class="login_btn"> 登&nbsp;陆</button>
                            </div>

                            <div class="space-4"></div>
                        </fieldset>
                    </div>
                    <div class="social-or-login center">
                        <span class="bigger-110">通知</span>
                    </div>

                    <div class="social-login ">
                        为了更好的体验性，本网站系统不再对IE8（含IE8）以下浏览器支持，请见谅。
                    </div>
                </div><!-- /login-main -->


                <!-- /widget-body -->
            </div><!-- /login-box -->
        </div><!-- /position-relative -->
    </div>
</div>
<div class="loginbm">版权所有 2016 <a href=""></a></div>
<strong></strong>
</body>
</html>
<script type="text/javascript">
    $(function () {
        /**
         * 默认加载验证码
         */
        $.ajax({
            url: "/admin/getValicode",
            dataType: "text",
            success: function (img, status) {
                $("#checkImg").attr("src", "data:image/png;base64," + img);
            },
            error: function (data) {
                alert('响应失败！');
            },
        })
    })
    /**
     * 点击更换验证码
     */
    $(".Codes_region").click(function () {
        $.ajax({
            url: "/admin/getValicode",
            dataType: "text",
            success: function (img, status) {
                $("#checkImg").attr("src", "data:image/png;base64," + img);
            },
            error: function (data) {
                alert('响应失败！');
            },
        })
    })
    $('#login_btn').on('click', function () {
        var username = $("#username").val();
        var password = $("#userpwd").val();
        var Codes_text = $("#Codes_text").val();
        if (username != null && username != "") {
            if (password != null && password != "") {
                if (Codes_text != null && Codes_text != "") {
                    $.ajax({
                        url: "/admin/backstageLogin",
                        method: "POST",
                        data: {
                            username: username,
                            password: password,
                            codes_text: Codes_text,
                        },
                        dataType: "text",
                        success: function (data) {
                            if (data == 0) {
                                layer.msg('验证码输入错误');
                            } else if (data == 1) {
                                layer.msg('登录成功');
                                var avar=window.setTimeout(function () {
                                    location.href = "/admin/shops_index";
                                    window.clearTimeout(avar)
                                },1000);

                            }else if(data==2){
                                layer.msg('用户名或密码错误!');
                            } else if (data == 3) {
                                var code = window.prompt("请填写您的邀请码！")
                                $.ajax({
                                    url: "/admin/judgeCoed",
                                    method: "POST",
                                    data: {
                                        code: code,
                                    },
                                    dataType: "text",
                                    success: function (data) {
                                        if(data>0){
                                            $.ajax({
                                                url: "/admin/addOneLoginSession",
                                                method: "POST",
                                                data: {
                                                    username: username,
                                                    password: password,
                                                },
                                                dataType: "text",
                                                success: function (data) {
                                                    if (data > 0) {
                                                        layer.msg('登录成功,已激活');
                                                        var avar=window.setTimeout(function () {
                                                            location.href = "/admin/shops_index?status=激活";
                                                            window.clearTimeout(avar)
                                                        },1000);

                                                    } else {
                                                        layer.msg('失败');
                                                    }
                                                }
                                            })
                                        } else {
                                            layer.msg('邀请码输入错误，或有效时间过期');
                                        }
                                    }
                                })
                            }
                        }
                    })
                } else {
                    layer.msg('请输入验证码');
                    return;
                }
            } else {
                layer.msg('请输入密码');
                return;
            }
        } else {
            layer.msg('请输入用户名');
            return;
        }

    })
    ;
    $(document).ready(function () {
        $("input[type='text'],input[type='password']").blur(function () {
            var $el = $(this);
            var $parent = $el.parent();
            $parent.attr('class', 'frame_style').removeClass(' form_error');
            if ($el.val() == '') {
                $parent.attr('class', 'frame_style').addClass(' form_error');
            }
        });
        $("input[type='text'],input[type='password']").focus(function () {
            var $el = $(this);
            var $parent = $el.parent();
            $parent.attr('class', 'frame_style').removeClass(' form_errors');
            if ($el.val() == '') {
                $parent.attr('class', 'frame_style').addClass(' form_errors');
            } else {
                $parent.attr('class', 'frame_style').removeClass(' form_errors');
            }
        });
    })
</script>
